package Example.singleton;

import annoations.ThreadSafe;

/**
 * 饿汉模式
 * 单例实例在类装载的时候实现
 * <p>
 * 不足：如果构造方法中有过多的操作，会导致类加载很慢
 *
 * @author Wang Renlei
 * @Date 2020/7/1
 */
@ThreadSafe
public class SingletonExample6 {

    //私有构造方法
    private SingletonExample6() {

    }

    //私有单例对象
    private static SingletonExample6 instance = null;

    //静态块
    static {
        instance = new SingletonExample6();
    }

    public static SingletonExample6 getInstance() {
        return instance;
    }

}
